<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>postMessage</title>
</head>
<body>
<p id="parpentId">这是父元素页面</p>
<!--<iframe src="http://localhost:63342/contract-ecp/html/28.1-postMessage1.html" frameborder="1" id="iframeId1" name="iframeName1"></iframe>-->
<!--<iframe src="http://localhost:63342/contract-ecp/html/28.2-postMessage2.html" frameborder="1" id="iframeId2" name="iframeName2"></iframe>-->
<iframe src="./28.1-postMessage1.html" frameborder="1" id="iframeId1" name="iframeName1"></iframe>
<iframe src="./28.2-postMessage2.html" frameborder="1" id="iframeId2" name="iframeName2"></iframe>
  <iframe src="http://127.0.0.1:8848/peacetime/html/28.3-iframe_kuayu.html?id=1&ids=2" frameborder="1" id="iframeId3" name="iframeName3"></iframe>

<script>
  window.addEventListener('message',function(e){
    console.log(e.data)
  }, true)
  /* 1. 通过iframe的id获取子页面的dom，然后通过contentWindow属性获取子窗口的window对象*/
  setTimeout(function () {
    // document.getElementById('iframeId1').contentWindow.frameFun1();
    // let _p1 = document.getElementById('iframeId1').contentWindow.document.getElementById('p1');
    // console.log(_p1);
  }, 100)
  /* 2. 通过iframe的name获取子页面的window对象*/
  setTimeout(function () {
    // iframeName1.window.frameFun1();
    // console.log(iframeName1.document.getElementById('p1'));
  }, 100)
  /* 3. 通过window对象的frames[]数组对象直接获取子iframe对象*/
  setTimeout(function () {
    // window.frames[0].frameFun1();
    // console.log(window.frames[0].document.getElementById('p1'));
    //
    // window.frames[1].frameFun2();
    // console.log(window.frames[1].document.getElementById('iframeIdFile2'));
  }, 100)

  function parentFun1() {
    console.log('这是parentFun1函数');
  }
</script>
</body>
</html>